package kr.co.doriclassic.dataEx;

import java.util.Arrays;

public class Stack implements Data{
	private String arrItem[];
	private int size;
	private int top;
	public Stack(int size) {
		this.size = size;
		this.arrItem = new String[size];
		this.top = -1;
	}

	@Override
	public void push(String item){
		if(!isFull())
			arrItem[++top]=item;
		else
			System.out.println("Stack is Full");
	}

	@Override
	public String pop(){
		if(!isEmpty()){
			return arrItem[top--];			
		}
		else{
			return "Stack is Empty";
		}
		
	}

	@Override
	public boolean isEmpty(){
		return top==-1;
	}

	@Override
	public boolean isFull(){		
		return top==size-1;
	}

	@Override
	public void prnStack(){
		for (int i = 0; i <= top; i++) {
			System.out.printf("[%s\t]",arrItem[i]);
		}
		System.out.println();
		//System.out.println(Arrays.toString(arrItem));
	}

	@Override
	public String toString() {
		return String.format("%s\n",Arrays.toString(arrItem));
	}		
}
